
import React, { Component } from 'react'

import {nanoid} from 'nanoid'

// import './index.css'

export default class index extends Component {

   handleKeyUp = (event) =>{

       const {Addtodo} = this.props

       const {target,keyCode} = event

       //判断回车键

        if(keyCode !== 13){

            return

        }

        //判断输入的是否为空

        if(target.value.trim()===''){

            alert('输入的内容不能为空')

            return

        }

        // 将newTodo传给App组件

        Addtodo({id:nanoid(),name:target.value,status:0})

        //置空

        target.value=''

   }

    render() {

        return (

            <div className="todo-header">
                
                <input onKeyUp={this.handleKeyUp} type="text" />

            </div>

        )

    }

}
